package com.qsl.ssyx.sys.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qsl.ssyx.common.result.Result;
import com.qsl.ssyx.model.sys.RegionWare;
import com.qsl.ssyx.sys.service.RegionWareService;
import com.qsl.ssyx.vo.sys.RegionWareQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 城市仓库关联表 前端控制器
 * </p>
 *
 * @author 青衫泪
 * @since 2023-08-08
 */
@Api(tags = "开通区域")
@RestController
@RequestMapping("/admin/sys/regionWare")
public class RegionWareController {

    @Autowired
    private RegionWareService regionWareService;


    @ApiOperation("条件分页查询")
    @GetMapping("{page}/{limit}")
    public Result selectPage(@ApiParam(value = "当前页") @PathVariable Integer page
            , @ApiParam(value = "每页记录数") @PathVariable Integer limit
            , @ApiParam(value = "关键字") RegionWareQueryVo regionWareQueryVo) {
        Page<RegionWare> pageParam = new Page<>(page, limit);
        IPage<RegionWare> model = regionWareService.selectPage(pageParam, regionWareQueryVo);
        return Result.ok(model);
    }

    @ApiOperation("新增")
    @PostMapping("save")
    public Result save(@RequestBody RegionWare regionWare) {
        boolean flag = regionWareService.save(regionWare);

        return Result.ok(flag);
    }

    @ApiOperation("根据Id查询")
    @PostMapping("getById/{Id}")
    public Result save(@ApiParam(value = "Id") @PathVariable Integer Id) {
        RegionWare regionWare = regionWareService.getById(Id);
        return Result.ok(regionWare);
    }

    @ApiOperation("修改")
    @PutMapping("update")
    public Result update(@RequestBody RegionWare regionWare) {
        boolean flag = regionWareService.updateById(regionWare);
        return Result.ok(flag);
    }

    @ApiOperation("删除")
    @DeleteMapping("remove/{Id}")
    public Result remove(@PathVariable Integer Id) {
        boolean flag = regionWareService.removeById(Id);
        return Result.ok(flag);
    }

    @ApiOperation("取消开通")
    @PutMapping("updateStatus/{Id}/{status}")
    public Result updateStatus(@ApiParam(value = "Id", required = true) @PathVariable Long Id
            , @ApiParam(value = "状态", required = true) @PathVariable Integer status) {
        boolean flag = regionWareService.updateStatus(Id, status);
        return Result.ok(flag);
    }
}

